package com.bw.module_store.view

import android.graphics.Color
import android.view.View
import androidx.activity.viewModels
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.lib_base.path.RouterPath
import com.bw.lib_common.view.BaseMvvmActivity
import com.bw.module_store.R
import com.bw.module_store.adapter.StoreMerchantAdapter
import com.bw.module_store.databinding.ActivityStoreMerchantBinding
import com.bw.module_store.viewmodel.StoreViewModel

/**
 * 智慧园区-01-商家推荐-v1.1-吴熙-20250512
 */
@Route(path =RouterPath.PATH_STORE_MERCHANT_ACTIVITY)
class StoreMerchantActivity : BaseMvvmActivity<ActivityStoreMerchantBinding>() {
    lateinit var storeMerchantAdapter: StoreMerchantAdapter
    private val viewModel : StoreViewModel by viewModels()


    override fun initView() {
        //头布局
        mDataBinding.title.text="申请记录"
        mDataBinding.title.setTextColor(Color.BLACK)
        mDataBinding.topbarStoreMerchant.setBackgroundColor(Color.WHITE)
        mDataBinding.goAdd.visibility=View.GONE
        mDataBinding.goBack.visibility=View.GONE
        mDataBinding.goBackBlack.visibility=View.VISIBLE
        mDataBinding.goBackBlack.setOnClickListener { finish() }

        storeMerchantAdapter=StoreMerchantAdapter()
        mDataBinding.rv.layoutManager=LinearLayoutManager(this)
        mDataBinding.rv.adapter=storeMerchantAdapter

        //获取列表
        viewModel.getMerchantList()

        //点击item跳转到详情
        storeMerchantAdapter.setOnItemClickListener{ adapter, view, position ->
            ARouter.getInstance().build("/merchantDetail/merchantDetail")
                .withInt("merchantId",storeMerchantAdapter.data[position].id)
                .navigation()
        }

    }

    override fun observeDataChange(){
        viewModel.getMerchantListSuccess.observe(this){
            storeMerchantAdapter.data.clear()
            storeMerchantAdapter.data.addAll(it)
            storeMerchantAdapter.notifyDataSetChanged()
        }
    }

    override fun getLayoutId(): Int = R.layout.activity_store_merchant

}